<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.8.3.min.js"></script>
</head>
<body>


    <form action="" method="post">
        账户:<input type="text" name="username" id="username" placeholder="请输入账户"/><br/>
        密码:<input type="password" name="password" id="password" placeholder="请输入密码"/><br/>
        <input type="button" id="btn" value="登录"/>
    </form>


    <script>
        $(function(){       //表示整个页面加载完之后执行
            //获取按钮，并添加点击事件，发送ajax
            $("#btn").click(function () {

                var username = $("#username").val();
                var password = $("#password").val();

                $.ajax({

                    url:"/login46",
                    type:"post",
                    data:'{"username":"'+username+'","password":"'+password+'"}',
                    contentType:"application/json",
                    dataType:"json",
                    success:function(data){
                        if(data.flag==true){
                            location.href='success.jsp'
                        }else{
                            alert(data.message)
                        }
                    }
                })
            })
        })
    </script>
</body>
</html>